from http import HTTPStatus

import pytest


@pytest.fixture
def parking_json():
    return {
        "address": "Nevskiy pr., 1",
        "opened": True,
        "count_places": 456,
        "count_available_places": 123,
    }


def test_create_parking_route(client, parking_json):
    response = client.post("/parkings/", json=parking_json)
    assert response.status_code == HTTPStatus.CREATED
    assert response.json == {"id": response.json["id"], **parking_json}


@pytest.mark.parametrize(
    "wrong_json",
    [
        {
            "address": "Nevskiy pr., 1",
            "opened": True,
            "count_places": 456,
        },
        {
            "address": "Nevskiy pr., 1",
            "opened": True,
            "count_available_places": 123,
        },
        {
            "opened": True,
            "count_places": 456,
            "count_available_places": 123,
        },
    ],
)
def test_create_parking_route_missing_fields(client, wrong_json):
    response = client.post("/parkings/", json=wrong_json)
    assert response.status_code == HTTPStatus.BAD_REQUEST
    assert (
        response.json.get("error")
        == "address, count_places, count_available_places fields are required"
    )
